package princessWorld;

import processing.core.*;

public class Critter {
	
	private PApplet p;
	
	private PVector position;
	private PVector velocity;
	private PVector velocityAdd;
	private float maxVelocity = 2f; 
	
	public Critter() {
	}
	
	public void setup(PApplet processing) {
		p = processing;
		
		float xPos = p.random(0, IPrincessWorld.SIZE.x);
		float yPos = p.random(0, IPrincessWorld.SIZE.y);
		float zPos = p.random(IPrincessWorld.SIZE.z, 0);
		
		position = new PVector(xPos, yPos, zPos);
		
		velocity = new PVector(p.random(-2f, 2f), p.random(-2f, 2f), p.random(-2f, 2f));
		velocity.limit(maxVelocity);
		
		velocityAdd = new PVector();
	}
	
	public void update(PVector vel) {
		velocityAdd.set(vel);		
	}
	
	public void draw() {	
		velocity.add(velocityAdd);
		velocity.limit(maxVelocity);
		
		position.add(velocity);
		
		p.fill(255);
		p.stroke(255);
		p.beginShape(PApplet.LINES);
			p.vertex(position.x, position.y, position.z);
			
			PVector line = new PVector();
			line.set(velocity);
			line.normalize();
			line.mult(5);
			p.vertex(position.x + line.x, position.y + line.y, position.z + line.z);
		p.endShape();
		
		p.noStroke();
	}
	
	public PVector getPosition() {
		return position;
	}
	
	public PVector getVelocity() {
		return velocity;
	}

}
